// 引入mongoose
const mongoose = require('mongoose')

// 连接数据库
// authSource=admin表示用认证来源是root管理员admin
mongoose.connect('mongodb://admin:123456@localhost/db02?authSource=admin')
const db = mongoose.connection
db.on('error', console.error.bind(console, 'connection error:')) 
db.once('open', () => {
  console.log('connection success')
})

module.exports = mongoose